package com.lanou.projecta_163news.fragment;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import android.widget.Toast;

import com.lanou.projecta_163news.base.BaseFragment;
import com.lanou.projecta_163news.fragment.mainAdapter.TopicRecyclerAdapter;
import com.lanou.projecta_163news.fragment.mainAdapter.TopicRecyclerItemListener;
import com.lanou.projecta_163news.fragment.mainAdapter.Topic;
import com.lanou.projecta_163news.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/3/8.
 */
public class TopicFragment extends BaseFragment implements TopicRecyclerItemListener {
    private RecyclerView recyclerView;
    private TopicRecyclerAdapter topicRecyclerAdapter;
    private List<Topic> topicsData;

    @Override
    protected void initView() {
        recyclerView = bindView(R.id.topic_recyclerview);
    }

    @Override
    protected void initData() {
        ininRecyclerView();

    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_topic;
    }

    @Override
    protected ViewGroup getNull() {
        return null;
    }

    private void ininRecyclerView(){
        topicRecyclerAdapter = new TopicRecyclerAdapter();
        recyclerView.setAdapter(topicRecyclerAdapter);
        GridLayoutManager gm= new GridLayoutManager(getContext(),1);
        gm.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(gm);

        topicsData = new ArrayList<>();
        for (int i = 0; i <1 ; i++) {
            topicsData.add(new Topic(R.drawable.amata,R.mipmap.ic_launcher,"阿玛塔T-14","俄罗斯现役最新型坦克 参加了 红场阅兵 一门140mm滑膛炮,一门20mm自动机关炮,一挺13mm机枪,装备有主动防御系统","军事","12344","等待中"));
            topicsData.add(new Topic(R.drawable.amata,R.mipmap.ic_launcher,"阿玛塔T-14","俄罗斯现役最新型坦克 参加了 红场阅兵 一门140mm滑膛炮,一门20mm自动机关炮,一挺13mm机枪,装备有主动防御系统","军事","12344","等待中"));
            topicsData.add(new Topic(R.drawable.amata,R.mipmap.ic_launcher,"阿玛塔T-14","俄罗斯现役最新型坦克 参加了 红场阅兵 一门140mm滑膛炮,一门20mm自动机关炮,一挺13mm机枪,装备有主动防御系统","军事","12344","等待中"));
            topicsData.add(new Topic(R.drawable.amata,R.mipmap.ic_launcher,"阿玛塔T-14","俄罗斯现役最新型坦克 参加了 红场阅兵 一门140mm滑膛炮,一门20mm自动机关炮,一挺13mm机枪,装备有主动防御系统","军事","12344","等待中"));
            topicsData.add(new Topic(R.drawable.amata,R.mipmap.ic_launcher,"阿玛塔T-14","俄罗斯现役最新型坦克 参加了 红场阅兵 一门140mm滑膛炮,一门20mm自动机关炮,一挺13mm机枪,装备有主动防御系统","军事","12344","等待中"));
            topicsData.add(new Topic(R.drawable.amata,R.mipmap.ic_launcher,"阿玛塔T-14","俄罗斯现役最新型坦克 参加了 红场阅兵 一门140mm滑膛炮,一门20mm自动机关炮,一挺13mm机枪,装备有主动防御系统","军事","12344","等待中"));
            topicsData.add(new Topic(R.drawable.amata,R.mipmap.ic_launcher,"阿玛塔T-14","俄罗斯现役最新型坦克 参加了 红场阅兵 一门140mm滑膛炮,一门20mm自动机关炮,一挺13mm机枪,装备有主动防御系统","军事","12344","等待中"));
            topicsData.add(new Topic(R.drawable.amata,R.mipmap.ic_launcher,"阿玛塔T-14","俄罗斯现役最新型坦克 参加了 红场阅兵 一门140mm滑膛炮,一门20mm自动机关炮,一挺13mm机枪,装备有主动防御系统","军事","12344","等待中"));
            topicsData.add(new Topic(R.drawable.amata,R.mipmap.ic_launcher,"阿玛塔T-14","俄罗斯现役最新型坦克 参加了 红场阅兵 一门140mm滑膛炮,一门20mm自动机关炮,一挺13mm机枪,装备有主动防御系统","军事","12344","等待中"));
        }
        topicRecyclerAdapter.addToData(topicsData);
        topicRecyclerAdapter.setToRvItemListener(this);
    }

    @Override
    public void toRvItemListener(Topic topic) {
        Toast.makeText(getActivity(),topic.getTopicConTv().toString(),Toast.LENGTH_SHORT).show();
    }
}
